﻿using System.Collections.Generic;
using System.Windows.Forms;
using Generator.Selections.DataBase;
using Generator.Selections.DataDictionary;
using Generator.Selections.Repository;

namespace Generator.Selections.Windows
{
    public  class StartGeneratorSelection
    {
        public List<Table> SelectedTables { get; private set; }
        public string NameSpace { get;  set; }

        public void Execute()
        {
            if (!string.IsNullOrEmpty(ConnectionHandler.Instance.CheckConnection()))
            {
                var l = new Logon();
                var dr1 = l.ShowDialog();
                if (dr1 != DialogResult.OK)
                {
                    return;
                }
            }

            var f = new TableSelectionForm();
            f.Init();
            f.NameSpace = NameSpace;
            var dr = f.ShowDialog();

            if (dr == DialogResult.OK)
            {
                SelectedTables = f.SelectedTables;
                NameSpace = f.NameSpace;
                RelationRepository.GetRelations(SelectedTables);
            }
        }
    }
}
